package models

// 服务器信息

import (
	"github.com/beego/beego/v2/client/orm"
)

type ServerInfo struct {
	BModel
	Memo          string `orm:"column(memo);" json:"memo" form:"memo"`                              //备注
	ServerAddress string `orm:"column(server_address)" json:"server_address" form:"server_address"` // 服务器地址
	UserName      string `orm:"column(user_name)" json:"user_name" form:"user_name"`                // 登录用户名
	Password      string `orm:"column(password)" json:"password" form:"password"`                   // 登录密码
	AliasName     string `orm:"column(alias_name)" json:"alias_name" form:"alias_name"`             // 服务器别名
}

func NewServerInfo() *ServerInfo {
	return &ServerInfo{}
}

// 表名
func (ServerInfo) TableName() string {
	return ServerInfoTable
}

func (tb *ServerInfo) GetByPage(pageSize, pageIndex uint64) (lst []ServerInfo, count uint64, err error) {
	db := orm.NewOrm()
	offset := (pageIndex - 1) * pageSize
	q := db.QueryTable(NewServerInfo())
	var c int64
	c, err = q.Count()
	count = uint64(c)
	q.Offset(offset).Limit(pageSize).All(&lst)
	return
}

func (tb *ServerInfo) Find(id uint64) (m *ServerInfo, err error) {
	db := orm.NewOrm()
	m = &ServerInfo{}
	err = db.QueryTable(NewServerInfo()).Filter("id", id).One(m)
	if m.ID <= 0 {
		m = nil
	}
	return
}
